#!/usr/bin/env python
import os,sys,re,csv
import numpy as np
from networkx import Graph
from SpectralMix import DistanceMatrix
from SpectralMix import SpectralCluster
from SpectralMix.DataManipLib import make_input_graph
from examples_data import data1, data2

sys.path.append(os.path.join("..","tests","data"))
from examples_data import data1, data2
#from GenesExample import geneList, geneLabels, geneDistDict



########################################## example 1 ########################################## 
print "Example 1 -- genes from two different biological pathways"
k = 2         # number of clusters
sigma = 0.14  # bandwith parameter

## put the data into graph form
geneList = data1['geneList'] 
geneDistDict = data1['edges']
geneLabels = data1['labels']
G = make_input_graph(geneDistDict,geneList)

## run spectral clustering on original data 
np.random.seed(1234)
sc = SpectralCluster(G,k=k,dataHeader=geneList,labels=geneLabels,projID=os.path.join(".","temp"),                                   
                     dtype='graph',weighted=True,verbose=True,sigma=sigma,penalty=True)     
#sc.make_plot('graph',labels=sc.clustResults['labels'],name='example1')
centroids = sc.clustResults['centroids']                                                                                                                                
newLabels = sc.clustResults['labels']  

print "fscore", sc.evaluation['f1score'], "\n"


########################################## example 2 ########################################## 
print "Example 2 -- genes from four different biological pathways"
k = 4         # number of clusters
sigma = 0.5   # bandwith parameter

## put the data into graph form
geneList = data2['geneList'] 
geneDistDict = data2['edges']
geneLabels = data2['labels']
G = make_input_graph(geneDistDict,geneList)

## run spectral clustering on original data 
np.random.seed(9999)
sc = SpectralCluster(G,k=k,dataHeader=geneList,labels=geneLabels,projID=os.path.join(".","temp"),                                   
                     dtype='graph',weighted=True,verbose=True,sigma=sigma,penalty=True)     

centroids = sc.clustResults['centroids']                                                                                                                                                            
newLabels = sc.clustResults['labels']  

print "fscore", sc.evaluation['f1score'], "\n"
